import { store } from "@/store"
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { showError } from '@/utils/msg-show'
import { getPageApi } from '@/api/sys/userRate'

export const useUserRateStore = defineStore("UserRate", () => {

	const isZero = ref(true)
    const dataList = ref<any[]>([])
    const query = reactive<any>({
        pageNum: 1,
        pageSize: 10,
        totalSize: 0,
    })


	/** 获取默认费率 */
	async function getPage(){
		await getPageApi(query).then((res: any) => {
			query.totalSize = res.data.total
			if(query.pageNum == 1){
				dataList.value = res.data.list
			}else{
				dataList.value = dataList.value.concat(res.data.list)
			}
		}).catch(err => {
			showError(err.msg || err.errMsg || err)
		})
	}

	/** 初始化 */
	async function init() {
		if (isZero.value) {
            await getPage()
			isZero.value = false
		}
	}

   
	return {
		init, getPage,
        query, dataList,
	}

})

export function useUserRateStoreHook() {
	return useUserRateStore(store);
}